<!doctype html>
<html>
<head>
	<meta charset="utf-8"><meta name="format-detection" content="telephone=no">
	<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
	<title>我的</title>
	<link rel="stylesheet" type="text/css" href="../../lib/css/skin.css"/>
</head>
<body>
<div id="root">
	<div class="app_warp">

		<div class="app_head">
			<span class="left back"></span>
			<span class="name">学生信息</span>
			<span class="right">
				<a id="xiugai" href="javascript:;" tapmode onclick="xiugai()">修改</a>
			</span>
		</div>

		<div id="students" class="app_main"></div>

	</div>
</div>
<script id="student_template" type="text/html">
	<div class=" animated fadeIn">
		<div class="space"></div>
		<div class="app_box">
			<div class="box_tit">
			<span class="name">
				基本信息
			</span>
			</div>
			<div class="box_cont list_box">
				<ul class="view_xuesheng">

					<li class="clearfix">

						<div class="col_l">
						<span class="tit">
							姓名
						</span>
							<span class="val">
							<%:=userData.name%>
						</span>
						</div>

						<div class="col_r">
						<span class="tit">
							文化分
						</span>
							<span class="val">
							<%:=userData.c_points%>
						</span>
						</div>

					</li>

					<li class="clearfix">

						<div class="col_l">
						<span class="tit">
							性别
						</span>
							<span class="val">
							<%:=userData.sex===1?'男':'女'%>
						</span>
						</div>

						<div class="col_r">
						<span class="tit">
							省份
						</span>
							<span class="val">
							<%:getAreaName=userData.s_province%>
						</span>
						</div>

					</li>

					<li class="clearfix">
						<div class="col">
						<span class="tit">
							年龄
						</span>
							<span class="val">
							<%:=userData.age%>
						</span>
						</div>
					</li>

					<li class="clearfix">
						<div class="col">
						<span class="tit">
							目标院校
						</span>
							<span class="val">
							<%:=userData.m_school.name%>
						</span>
						</div>
					</li>

					<li class="clearfix">
						<div class="col">
						<span class="tit">
							艺考方向
						</span>
							<span class="val">
							<% for(var fx in userData.curriculum){%>
								<%:getClassifyName=userData.curriculum[fx]%>
							<%}%>
						</span>
						</div>
					</li>

				</ul>
			</div>
		</div>

		<div class="app_box">
			<div class="box_tit">
			<span class="name">
				购买课程
			</span>
			</div>
			<div class="box_cont list_box clearfix bgw">
				<% if(userData.tcourse){%>
				<ul class="kecheng_list">
					<% for(var kc in userData.tcourse){%>
					<li class="clearfix">
						<div class="col">
						<span class="tit">
							<%:=(parseInt(kc)+1)%>
						</span>
							<span class="val">
							<%:=userData.tcourse[kc].name%> （<%:=userData.tcourse[kc].num%>份）
						</span>
						</div>
					</li>
					<%}%>
				</ul>
				<%}else{%>
				<div class="nocontent minisize animated fadeInUp bgw" style="position: relative;">
					<img src="../../lib/img/nocomment.png" class="minimize" alt="">
					<div class="text minimize">
						用户尚未购买课程
					</div>
				</div>
				<%}%>
			</div>
		</div>
	</div>
</script>
<script id="tcourse_template" type="text/html">
	<div class="step animated fadeIn">

		<span style="padding: 2rem;text-align: center;display: block;">
			修改学生所购买的课程
		</span>
		<ul id="tcourse_sels">
			<%for(var kc in tcourse){%>
			<li data_id="<%:=tcourse[kc].id%>">
				<%:=tcourse[kc].name%>
			</li>
			<%}%>
		</ul>

	</div>
</script>
<script>

	var
		step = !0,
		tcourse,
		userData = null,
		findeSchool = false,
		initTcourse = function () {
			_$.template('tcourse_template', {tcourse:tcourse,userData:userData}, function (html) {
				$('#students').html(html);
				$('#xiugai').text('保存');
				$('#tcourse_sels li').off('click').on('click',function(){
					$(this).toggleClass('active');
					var _all = $('#tcourse_sels li.active');
					if (_all.length > 0) {
						userData.tcourse = [];
						for (var i = 0; i < _all.length; i++) {
							userData.tcourse.push(_all.eq(i).attr('data_id'));
						}
					} else {
						userData.tcourse = null;
					}
				})
			});
		},
		initUserHtml = function () {
			$('#xiugai').text('修改');
			_$.template('student_template', {tcourse:tcourse,userData:userData}, function (html) {
				$('#students').html(html);
			});
		},
		xiugai = function () {
			if (step === !0) {
				step = !step;
				initTcourse()
			} else {
				_$.ajax({
					interface:'addTcourse',
					data: {
						sid:userData.id,
						tid:userData.tcourse
					},
					call:function (data) {
						if(data.status===200){
							api.execScript({
								name:'xuesheng',
								script:'loadData()'
							})
							api.toast({
								msg: '修改成功'
							})
							_$.sleep(function(){
								api.closeWin();
							},1500);
						}else{
							api.toast({
								msg:data.msg
							})
							return false;
						}
					}
				})
			}
		},
		appready = function () {

			if (_$.getType(api.pageParam.student) !== 'undefined') {
				api.toast({
					msg: api.pageParam.student.name + '已经成为您机构下的用户'
				})
				userData = api.pageParam.student;
			} else if (_$.getType(api.pageParam) !== 'undefined') {
				userData = api.pageParam;
			} else {
				api.toast({
					msg: '未能得到用户数据'
				})
				_$.sleep(function () {
					api.closeWin();
				}, 2000);
				return false;
			}

			_$.db.get({
				call: function (udb) {
					tcourse = udb.tcourse
				}
			})

			_$.db.get({
				key: 'area',
				call: function (data) {
					window.__areaData__ = data;
				}
			})
			for (var i in schoolData) {
				for (var j in schoolData[i]) {
					if (!findeSchool && schoolData[i][j].id === userData.m_school) {
						findeSchool = !findeSchool;
						userData.m_school = schoolData[i][j];
					}
				}
			}
			initUserHtml();
		};
</script>
<script src="../../lib/js/config.js"></script>
<script src="../../lib/js/schoolData.js"></script>
<script src="../../lib/js/jquery.js"></script>
<script src="../../lib/js/common.js"></script>
</body>
</html>